<template>
<!-- 审核人员 发布藏品审核-->
    <div class="hotel-book">
        <div class="crumbs">
            <el-breadcrumb separator="/">
                <el-breadcrumb-item><i class="el-icon-message"></i> 发布藏品审核列表</el-breadcrumb-item>
            </el-breadcrumb>
        </div>
        <div class="container">
            <!--内容-->
            <el-tabs v-model="message"  @tab-click="handleClick">
                <el-tab-pane label="待审核" name="first">
                </el-tab-pane>
                <el-tab-pane label="审核通过" name="second">
                </el-tab-pane>
                <el-tab-pane label="审核不通过" name="three">
                </el-tab-pane>
                <div style="height:40px"></div>
                    <!-- <el-form :inline="true" class="demo-form-inline">
                        <el-form-item label="联系人">
                            <el-input v-model="contact" clearable placeholder="请输入联系人名称" style="width:250px;"></el-input>
                        </el-form-item>
                        <el-form-item label="联系电话">
                            <el-input v-model="mobile" clearable   placeholder="请输入联系电话" style="width:250px;"></el-input>
                        </el-form-item>
                        <el-form-item>
                            <el-button type="primary" @click="onSubmit"> &nbsp;&nbsp;查询&nbsp;&nbsp;  </el-button>
                        </el-form-item>
                    </el-form> -->
                    <el-table :data="tableData"  style="width: 100%" >
                        <el-table-column prop="id" label="ID" width="80" align="center">
                        </el-table-column>
                        <el-table-column prop="title_cn" label="藏品名称"  align="center">
                        </el-table-column>
                        <el-table-column prop="category" label="所属分类（一级/二级/三级）"   align="center">
                        </el-table-column>
                        <el-table-column prop="price" label="价格" width="80" align="center">
                        </el-table-column>
                        <el-table-column prop="city" label="城市" width="100" align="center">
                        </el-table-column>
                        <el-table-column prop="stock" label="数量" width="100" align="center">
                        </el-table-column>
                        <el-table-column prop="create_time" label="下单时间" width="170" align="center">
                        </el-table-column>

                        <el-table-column prop="stateTxt" label="状态" width="80" align="center">
                        </el-table-column>
                        <el-table-column label="操作"  width="160"   align="center">
                            <template slot-scope="scope" >
                                <el-button size="small" type="text" @click="handleEdit(scope.$index, scope.row)" v-show="isShowHandle">处理</el-button>
                                <el-button size="small" type="text" @click="handleLook(scope.$index, scope.row)" >查看</el-button>
                            </template>
                            
                        </el-table-column>
                    </el-table>
                    <div class="pagination" v-show="totalPages>1">
                        <el-pagination v-if="paginationShow" @current-change="handleCurrentChange"  layout="total,prev, pager, next" :total="totalElements">
                        </el-pagination>
                    </div>
            </el-tabs>
            <!--/内容-->
             <!-- 新增编辑弹出框 -->
            <el-dialog title="藏品审核处理" :visible.sync="editVisible"  center >
                <el-form style="width:700px; margin:0 auto"  label-width="110px">
                    <el-form-item label="审核结果：">
                            <el-select v-model="type" placeholder="请选择"> 
                                <el-option v-for="item in typeOptions" :key="item.url" :label="item.label" :value="item.url">
                                </el-option>
                            </el-select>
                    </el-form-item> 
                    <el-form-item label="中文标题：">
                        <el-input style="width:520px;"  v-model="titleCn"  placeholder="请输入中文标题" ></el-input>
                    </el-form-item>
                    <el-form-item label="英文标题：">
                        <el-input style="width:520px;"  v-model="titleEn"  placeholder="请输入英文标题" ></el-input>
                    </el-form-item>
                    <el-form-item label="中文来源：">
                        <el-input style="width:520px;"   v-model="sourceCn" placeholder="请输入中文来源"></el-input>
                    </el-form-item>
                    <el-form-item label="英文来源：">
                        <el-input style="width:520px;"  v-model="sourceEn" placeholder="请输入英文来源"></el-input>
                    </el-form-item>
                    <el-form-item label="中文品相：">
                        <el-input style="width:520px;"  v-model="outViewCn" placeholder="请输入中文品相"></el-input>
                    </el-form-item>
                    <el-form-item label="英文品相：">
                        <el-input style="width:520px;"  v-model="outViewEn" placeholder="请输入英文品相"></el-input>
                    </el-form-item>
                    <el-form-item label="中文描述：">
                    	<el-input style="width:520px;" type="textarea" v-model="descriptionCn" placeholder="请输入中文描述"></el-input>
                	</el-form-item>
                    <el-form-item label="英文描述：">
                    	<el-input style="width:520px;" type="textarea" v-model="descriptionEn" placeholder="请输入英文描述"></el-input>
                	</el-form-item>
                </el-form>
                <div slot="footer" class="dialog-footer">
                    <el-button type="primary" @click="saveSend()">确 定</el-button>
                </div>
            </el-dialog>
        </div>
    </div>
</template>
<script>
import { getpubCheckList, postCheckPublish } from "@/api/subsection/publish";
export default {
    name:'agreeList',
    data() {
        return {
            message: 'first',
            state:1, //tabs状态：0所有、1待审核、2审核通过、3审核不通过
            types:0,//类型：0不限、1精品推荐、2每周精选
            categoryLevel1:0,//	一级分类ID、传0为全部
            paginationShow:true,//重新显示分页
            pageIndex:1,//当前页码
            pageSize:10,//每页10条
            totalElements:1,//默认的总条数
            totalPages:1,//默认的总页数
            tableData:[],//表格数据
            delIndex:0, //当前选中的下标
            delId:0,  //当前对象Id
            editVisible:false, //默认dialog 不弹出
            isShowHandle:true,//是否显示操作按钮
            typeOptions:[{url:2,label:"审核通过"},{url:3,label:"审核不通过"},],//平台类型：1安卓、2IOS
            type:'',//审核结果状态：2审核通过，3审核不通过
            titleCn:'',//中文标题
            titleEn:'',//英文标题
            sourceCn:'',//中文来源
            sourceEn:'',//英文来源
            outViewCn:'',//中文品相
            outViewEn:'',//英文品相
            descriptionCn:'',//中文描述
            descriptionEn:'',//英文描述
        }
    },
    created(){
        //获取待处理的数据
        this.getAgree(0);
    },
    methods: {
        //点击tabs切换数据
        handleClick(tab, event) {
            this.pageIndex = 1;
            this.paginationShow = false   //分页器消失
            this.$nextTick(function () {
                //分页器重新加载 解决element 分页器的无法触发current-change事件 只限在tabs页 
                this.paginationShow = true  
            }) 

            if(this.message=="first"){
                this.isShowHandle = true;
                this.state = 1; //状态：0所有、1待审核、2审核通过、3审核不通过
                this.getAgree();
               
            }else if(this.message=="second"){
                this.state = 2;
                 this.isShowHandle = false;
                this.getAgree();
            }else{
                this.state = 3;
                 this.isShowHandle = false;
                this.getAgree(); 
            }

        },
        //获取预约管理的列表数据
        getAgree(){
            //timeout:0不筛选  1 筛选未就餐且已过期的订单
            var param = {
                state:this.state,
                type:this.types,
                categoryLevel1:this.categoryLevel1,
                pageIndex: this.pageIndex,
                pageSize: this.pageSize
            };
            getpubCheckList(this.state,this.types,this.categoryLevel1, this.pageIndex, this.pageSize).then(response => {
                // console.log(response);
                if (response.code == 200) {
                    var data = response.data; //当前返回的数据
                    this.tableData = data.list; //列表数据
                    this.totalElements = data.total; //总条数
                    this.totalPages = Math.ceil(data.total / this.pageSize); //总页数
                   
                    for(let i =0 ;i< this.tableData.length; i++ ){
                        //根据数据状态进行判断
                        if(this.state == 1){//进行中
                            this.tableData[i].stateTxt = "待审核"
                        }else if(this.state == 2){
                            this.tableData[i].stateTxt = "通过"
                        }else{
                            this.tableData[i].stateTxt = "不通过"
                        }
                        this.tableData[i].category = this.tableData[i].category_name1 + " / "+this.tableData[i].category_name2 + " / "+this.tableData[i].category_name3;

                    } 
                } else {
                this.$notify.error({
                    title: "异常",
                    offset: 100,
                    message: response.msg
                });
                }
            });
            
        },
        //分页
        handleCurrentChange(val){
            if(val){
                this.pageIndex = val;
                this.getAgree(); 
            }
        },
        //处理
        handleEdit (index,row){
            if(row.id && row.id>0){
                this.delIndex = index;
                this.delId = row.id; //记录当前对象ID
                this.editVisible = true; //显示兑换弹出框
                this.titleCn = row.title_cn; 
                this.titleEn = row.title_en;
                this.sourceCn = row.source_cn;
                this.sourceEn = row.source_en;
                this.outViewCn = row.out_view_cn;
                this.outViewEn = row.out_view_en;
                this.descriptionCn = row.description_cn;
                this.descriptionEn = row.description_en;

            }
        },
        //审核确定操作
        saveSend(){
            let _this = this;
            //先判断输入情况
            if(this.type == 2){
                if(this.type==""){
                    this.$notify.info({title: '提示',message: '请先选择审核结果'});
                    return false;
                }
                if(this.titleCn==""){
                    this.$notify.info({title: '提示',message: '请先输入中文标题'});
                    return false;
                }
                if(this.titleEn==""){
                    this.$notify.info({title: '提示',message: '请先输入英文标题'});
                    return false;
                }
                if(this.sourceCn == ""){
                    this.$notify.info({title: '提示',message: '请先输入中文来源'});
                    return false;
                }
                if(this.sourceEn == ""){
                    this.$notify.info({title: '提示',message: '请先输入英文来源'});
                    return false;
                }
                if(this.outViewCn == ""){
                    this.$notify.info({title: '提示',message: '请先输入中文品相'});
                    return false;
                }
                if(this.outViewEn == ""){
                    this.$notify.info({title: '提示',message: '请先输入英文品相'});
                    return false;
                }
                    if(this.descriptionCn == ""){
                    this.$notify.info({title: '提示',message: '请先输入中文描述'});
                    return false;
                }
                if(this.descriptionEn == ""){
                    this.$notify.info({title: '提示',message: '请先输入英文描述'});
                    return false;
                }
                this.postCheckPublish();
            }else {
                this.postCheckPublish();
            }
        },
        //提交方法
        postCheckPublish(){
            var _this = this;
            let param = {};
            param.goodsId = _this.delId;
            param.state = _this.type;
            param.titleCn = _this.titleCn;
            param.titleEn = _this.titleEn;
            param.sourceCn = _this.sourceCn;
            param.sourceEn = _this.sourceEn;
            param.outViewCn = _this.outViewCn;
            param.outViewEn = _this.outViewEn;
            param.descriptionCn = _this.descriptionCn;
            param.descriptionEn = _this.descriptionEn;
            postCheckPublish(param).then(response => {
                // console.log(response);
                if (response.code == 200) {
                    this.$message({
                        message: '恭喜你，操作成功',
                        type: 'success'
                    });
                    setTimeout(function(){
                        _this.editVisible = false;
                        _this.getAgree(0);
                    },2000);
                }else{
                    _this.$notify.error({
                        title: '操作失败，请重试',
                        duration:2000,
                        message: '失败原因：'+response.msg
                    });
                }
            }).catch(error=>{
                // console.log(error); 
            }); 
        },
        //查看详情
        handleLook(index,row){
            if(row.id &&row.id>0){
                this.$router.push({ path: '/subsection/details',query:{id:row.id}});
            }
        },
    },
}
</script>
<style lang="stylus" scoped>
.bs-callout {
    padding: 20px;
    border: 1px solid #eee;
    border-left-width: 5px;
    border-radius: 3px;
}
    .bs-callout-danger {
    border-left-color: #ce4844;
}
</style>


